package com.hisan.freeride.home.adapter;

import com.github.library.BaseQuickAdapter;
import com.github.library.BaseViewHolder;
import com.hisan.freeride.R;
import com.hisan.freeride.common.utils.CollectionUtils;
import com.hisan.freeride.home.model.RideUser;

import java.util.List;

/**
 * 常用联系人适配器
 * Created by yu on 2017/1/17.
 */

public class RideUserdapter extends BaseQuickAdapter<RideUser,BaseViewHolder>{

    private ButtonClickListener mButtonClickListener;
    private ItemClickListener mItemClickListener;

    public RideUserdapter(List<RideUser> data) {
        super(R.layout.ride_item,data);
    }


    @Override
    protected void convert(BaseViewHolder holder, final RideUser item) {
        holder.getView(R.id.intervalLin).setOnClickListener(v -> {
            if (!CollectionUtils.isNullOrEmpty(mItemClickListener)){
                mItemClickListener.onItemClick(item);
            }
        });
        holder.setText(R.id.name, item.getName());
        holder.setText(R.id.type, item.getCard_type()+" "+item.getCard_number()+"");
        holder.getView(R.id.delete).setOnClickListener(v -> {
            if (mButtonClickListener!=null){
                mButtonClickListener.onClick(item);
            }
        });
    }

    public void setButtonClickListener(ButtonClickListener listener) {
        mButtonClickListener = listener;
    }
    public void setItemClickListener(ItemClickListener listener) {
        mItemClickListener = listener;
    }

    /**
     * 按钮的点击监听
     */
    public interface ButtonClickListener {
        void onClick(RideUser data);
    }

    /**
     * item的点击监听
     */
    public interface ItemClickListener {
        void onItemClick(RideUser data);
    }


}
